//# sourceURL=http://uMapApp/UI/IconMenu/IconMenuSlideButton
define([
    "mhjs/mhjs"
], function (
    mhjs
) {

    function IconMenuSlideButton(option) {
        var _this = this;
        _this.dom = $("<div class='iconMenuSlideButton'><img/><div class='iconMenuSlideButtonLabel'></div></div>");

        _this.isActive = false;
        _this.isEnable = false;

        _this.dom.click(function () {
            if (_this.isEnable) {
                _this.toggleActive();
                _this.type !== "checkbox" && _this.parent.parent.parent.checkActive();
            }
        });

        _this.title = option.title;
        _this.icon = option.icon;
        _this.type = option.type;

        if (option.type === "checkbox" && option.bindingCheckbox) {
            _this.bindingCheckbox = option.bindingCheckbox;
        } else {
            _this.onActive = option.onActive;
            _this.onInactive = option.onInactive;
        }
    }

    var _class = IconMenuSlideButton;

    mhjs.Inherit(_class, mhjs.Div);

    Object.defineProperties(_class.prototype, {
        "icon"           : {
            set: function (icon) {
                var _this = this;
                _this._icon = icon;
                _this.dom.find("img").attr("src", icon);
            },
            get: function () {
                return this._icon;
            }
        },
        "title"          : {
            set: function (title) {
                var _this = this;
                _this._title = title;
                _this.dom.find(".iconMenuSlideButtonLabel").text(title);
            },
            get: function () {
                return this._title;
            }
        },
        "active"         : {
            value: function () {
                if (!this.isActive) {
                    this._onActive && this._onActive(this);
                }
                this.dom.addClass("active");
                this.isActive = true;
            }
        },
        "onActive"       : {
            set: function (fun) {
                var _this = this;

                if (fun) {
                    _this._onActive = fun;
                    _this.enable();
                } else {
                    _this.disable();
                }

            },
            get: function () {
                return this._onActive;
            }
        },
        "inactive"       : {
            value: function () {

                if (this.isActive) {
                    this._onInactive && this._onInactive(this);
                }

                this.dom.removeClass("active");
                this.isActive = false;
            }
        },
        "onInactive"     : {
            set: function (fun) {
                var _this = this;
                _this._onInactive = fun;
            },
            get: function () {
                return this._onInactive;
            }
        },
        "toggleActive"   : {
            value: function () {
                if (this.isActive) {
                    this.inactive();
                } else {
                    this.active();
                }
            }
        },
        "enable"         : {
            value: function () {
                this.dom.removeClass("disable");
                this.isEnable = true;
            }
        },
        "disable"        : {
            value: function () {
                this.dom.addClass("disable");
                this.isEnable = false;
            }
        },
        "toggleEnable"   : {
            value: function () {
                if (this.isEnable) {
                    this.disable();
                } else {
                    this.enable();
                }
            }
        },
        "type"           : {
            set: function (type) {
                var _this = this;
                if (type === "checkbox") {
                    _this._type = type;
                    _this.dom.addClass("checkbox");
                }
            },
            get: function () {
                return this._type;
            }
        },
        "bindingCheckbox": {
            set: function (checkbox) {
                var _this = this;

                if (checkbox) {

                    if (checkbox.isEnable) {
                        this.enable();

                        this.dom.toggleClass("active", checkbox.isChecked);
                        this.isActive = checkbox.isChecked;

                        _this.onActive = function () {
                            checkbox.check();
                        };
                        _this.onInactive = function () {
                            checkbox.unCheck();
                        };

                    } else {
                        this.disable();
                    }


                }

            },
            get: function () {
                return this._type;
            }
        }
    });

    return _class;

});